/**
*	@file    \A\2.cpp
*	@date    2013-10-6 17:15
*	@author  Il'yas Garipov <logirz728@gmail.com>
*
*	Matrix transposer.
*
*	@version 1.0
*
*	@par On input: first row has a single number - n.
*	@par Following n rows have n numbers each - thus is the matrix defined.
*	@par Output has, similarly, n rows with n nums each - the transposed matrix itself
*/


#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

#ifndef NDEBUG
	#define DOUT( toprint ) printf( "\n# " toprint )	//!< Debug output, prints a plain text line preceded by #
	#define DPUT( toput , x ) printf( "\n# " toput , x )//!< Debug put, a DOUT with a single variable inside
	#define DLN											//!< Debug line, doesn't exist in release (with NDEBUG defined)
	#define DPUTCLOSURE	DOUT("=============================================================================");\
						DPUT("FILE: %s", __FILE__ );\
						DPUT("COMPILATION DATE: %s", __DATE__ );\
						DPUT("COMPILATION TIME: %s", __TIME__ )//!< Put a closing statement, complete with datestamp and finename.
#else
	#define DOUT
	#define DPUT
	#define DLN if(0)
	#define DPUTCLOSURE
#endif

int main()
{
	DOUT("=======================2007, 1 semester assignment, 2-A=======================");
	DOUT("==============================================================================");
	DOUT("Please enter n which is the amount of rows and columns in the matrix (0<n<50):");
	DOUT(">");

	int n = 0;
	int chk = scanf("%d", &n);
	DLN assert(("You have entered a single number" , chk == 1));
	DLN assert(("The number entered is smaller than 50" , n < 50));

	DPUT("Please submit the matrix itself: row-by-row, %d numbers in each", n);
	DOUT(">");

	long long int* nMatr = (long long int*) calloc((n * n), sizeof(*nMatr));
	DLN assert(("A matrix was successfully created" , (nMatr != NULL)));

	for(int i = 0; i < (n * n); i++) {
		chk = scanf("%lld", &nMatr[i]);
		DLN assert(("Garbage-less input" , chk == 1));
	}

	for(int i = 0; i < n; i++) {

		for(int j = 0; j < n; j++) {
			printf("%lld ", nMatr[(n * j) + i]);
		}

		printf("\n");

	}

	free(nMatr);

	DPUTCLOSURE;
	return 0;
}
